import requests, json
import datetime
import time

wx_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=0723f225-f7fe-4d89-a12b-039d760452bd"
# headers = {"content-type": "multipart/form-data; boundary=---011000010111000001101001"}

#response = requests.request("POST", url, data=payload, headers=headers)

# print(response.text)
def dcd():
    headers = {
               "content-type": "multipart/form-data; boundary=---011000010111000001101001"
               }
    payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"desName\"\r\n\r\n椒江 -- 上大陈\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"startTime\"\r\n\r\n2023-08-19\r\n-----011000010111000001101001--\r\n\r\n"

    url = "http://dzsw.jjlypw.com/st9pc/shiplist/listbus"


    r = requests.request("POST", url, data=payload.encode("utf-8"), headers=headers)
    data = r.json()  # 接口响应参数json化
    for it in data.get("data").get("shiplist"):
        if it.get("BusCode") == 'QD9X1':
            remain = it.get("NetsellQuantity")
            print(it.get("BusCode") + "还剩余:" +str(remain))
            if remain >= 0:
                send_msg("赶紧抢票======================"+it.get("BusCode") + "还剩余:" +str(remain) )
def send_msg(content):
    """艾特全部，并发送指定信息"""
    data = json.dumps({"msgtype": "text", "text": {"content": content, "mentioned_list":["@all"]}})
    r = requests.post(wx_url, data, auth=('Content-Type', 'application/json'))
    print(r.json)


if __name__ == '__main__':
    #send_msg('测试')
    #url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=0723f225-f7fe-4d89-a12b-039d760452bd"
    dcd()
